/**
 * @description 设置唯一值
 */
const getUUId = () => {
	return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
		var r = (Math.random() * 16) | 0,
			v = c == 'x' ? r : (r & 0x3) | 0x8;
		return v.toString(16);
	});
};

const getRouterParams = () => {
	const searchStr = window.location.hash.split('?')[1];
	const searchParams = new URLSearchParams(searchStr) as any;
	return Object.fromEntries(searchParams.entries());
};
const isNull = (data: any) => {
	let newObje: any;
	for (const key in data) {
		newObje[key] = data[key];
		if (data[key] === null) {
			newObje[key] = '';
		}
	}
	return newObje;
};
//翻译级联
const formatteCascader = (selectedIds: any, tree: any) => {
	// 初始化一个空数组来存放找到的名字
	let names: any = [];
	// 定义一个递归函数来遍历树
	function traverseTree(nodes: any) {
		nodes.forEach((node: any) => {
			// 检查当前节点的ID是否在选中ID数组中
			if (selectedIds.includes(node.value)) {
				// 如果是，将名字添加到结果数组中
				names.push(node.label);
			}
			// 如果节点有子节点，则递归遍历子节点
			if (node.children && node.children.length > 0) {
				traverseTree(node.children);
			}
		});
	}
	// 开始遍历树
	traverseTree(tree);
	// 返回包含名字的字符串
	return names.join(',');
};
export { getUUId, getRouterParams, isNull, formatteCascader };
